package gameobject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.swing.ImageIcon;
import javax.swing.JFrame;

import engine.JLeibniz;
import engine.MainFrame;

/**
 * The user class. Holds information about the current room,
 * the HP and the inventory.
 * 
 * @author Simon Dehne
 *
 */
public class User {
	
	private Room currentRoom;
	private Map<String, Object> inventory;
	JFrame mainFrame = JLeibniz.mainFrame;
	
	// path to the image and x/y positions
	private String image;
	private int xPos;
	private int yPos;
	private int destX;
	private int destY;
	
	public boolean moving = false;
	
	/**
	 * Initializes the inventory and starting position.
	 */
	public User() {
		inventory = new HashMap<String, Object>();
		
		// construct the path to the item image
		this.image = "res/user.png";		
		this.xPos = 248;
		this.yPos = 504;
		this.destX = xPos;
		this.destY = yPos;
	}
	
	public int getDestX() {
		return destX;
	}
	
	public int getDestY() {
		return destY;
	}
	
	public void setDestination(int x, int y) {
		destX = x;
		destY = y;
	}
	
	public int getX() {
		return xPos;
	}
	
	public int getY() {
		return yPos;
	}
	
	public void setX(int x) {
		this.xPos = x;
	}
	
	public void setY(int y) {
		this.yPos = y;
	}
	/**
	 * Getter for the current room the user is in.
	 * 
	 * @return	The room.
	 */
	public Room getCurrentRoom() {
		return currentRoom;
	}
	
	/**
	 * Changes the current room and display its description.
	 * 
	 * @param curRoom	The room.
	 */
	public void setCurrentRoom(Room curRoom) {
		currentRoom = curRoom;
		JLeibniz.output(currentRoom.getDescription());
	}

	/**
	 * Adds an object to the player's inventory.
	 * 
	 * @param name	The object's name
	 * @param obj	The object to be added.
	 */
	public void addToInv(Object obj) {
		inventory.put(obj.getName(), obj);
		((MainFrame) mainFrame).displayInv(obj);
	}
	
	/**
	 * Removes an object from the player's inventory.
	 * 
	 * @param obj	The object to be removed.
	 */
	public void removeFromInv(Object obj) {
		
		if(inventory.containsKey(obj.getName())) {
			inventory.remove(obj.getName());
			((MainFrame) mainFrame).removeFromInv(obj);
		}
	}
	
	/**
	 * Getter for the inventory.
	 * 
	 * @return The inventory.
	 */
	public Map<String, Object> getInventory() {
		return inventory;
	}
}
